// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   FitZoom.java

package org.achartengine.tools;

import org.achartengine.chart.*;
import org.achartengine.model.XYMultipleSeriesDataset;
import org.achartengine.model.XYSeries;
import org.achartengine.renderer.DefaultRenderer;
import org.achartengine.renderer.XYMultipleSeriesRenderer;

// Referenced classes of package org.achartengine.tools:
//			AbstractTool

public class FitZoom extends AbstractTool
{

	public FitZoom(AbstractChart abstractchart)
	{
		super(abstractchart);
	}

	public void apply()
	{
		if (mChart instanceof XYChart)
		{
			if (((XYChart)mChart).getDataset() == null)
				return;
			int i = mRenderer.getScalesCount();
			if (mRenderer.isInitialRangeSet())
			{
				for (int j = 0; j < i; j++)
					if (mRenderer.isInitialRangeSet(j))
						mRenderer.setRange(mRenderer.getInitialRange(j), j);

			} else
			{
				XYSeries axyseries[] = ((XYChart)mChart).getDataset().getSeries();
				Object obj = null;
				int k = axyseries.length;
				if (k > 0)
				{
					for (int l = 0; l < i; l++)
					{
						double ad[] = {
							1.7976931348623157E+308D, -1.7976931348623157E+308D, 1.7976931348623157E+308D, -1.7976931348623157E+308D
						};
						for (int i1 = 0; i1 < k; i1++)
							if (l == axyseries[i1].getScaleNumber())
							{
								ad[0] = Math.min(ad[0], axyseries[i1].getMinX());
								ad[1] = Math.max(ad[1], axyseries[i1].getMaxX());
								ad[2] = Math.min(ad[2], axyseries[i1].getMinY());
								ad[3] = Math.max(ad[3], axyseries[i1].getMaxY());
							}

						double d = Math.abs(ad[1] - ad[0]) / 40D;
						double d1 = Math.abs(ad[3] - ad[2]) / 40D;
						mRenderer.setRange(new double[] {
							ad[0] - d, ad[1] + d, ad[2] - d1, ad[3] + d1
						}, l);
					}

				}
			}
		} else
		{
			DefaultRenderer defaultrenderer = ((RoundChart)mChart).getRenderer();
			defaultrenderer.setScale(defaultrenderer.getOriginalScale());
		}
	}
}
